package com.ruoyi.web.controller.system;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ConstructionComplaint;
import com.ruoyi.system.service.IConstructionComplaintService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工投诉Controller
 * 
 * @author ruoyi
 * @date 2021-06-22
 */
@RestController
@RequestMapping("/system/complaint")
public class ConstructionComplaintController extends BaseController
{
    @Autowired
    private IConstructionComplaintService constructionComplaintService;

    /**
     * 查询施工投诉列表
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstructionComplaint constructionComplaint)
    {
        startPage();
        List<ConstructionComplaint> list = constructionComplaintService.selectConstructionComplaintList(constructionComplaint);
        return getDataTable(list);
    }

    /**
     * 导出施工投诉列表
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:export')")
    @Log(title = "施工投诉", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConstructionComplaint constructionComplaint)
    {
        List<ConstructionComplaint> list = constructionComplaintService.selectConstructionComplaintList(constructionComplaint);
        ExcelUtil<ConstructionComplaint> util = new ExcelUtil<ConstructionComplaint>(ConstructionComplaint.class);
        return util.exportExcel(list, "complaint");
    }

    /**
     * 获取施工投诉详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:query')")
    @GetMapping(value = "/{ccId}")
    public AjaxResult getInfo(@PathVariable("ccId") Long ccId)
    {
        return AjaxResult.success(constructionComplaintService.selectConstructionComplaintById(ccId));
    }

    /**
     * 新增施工投诉
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:add')")
    @Log(title = "施工投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructionComplaint constructionComplaint)
    {constructionComplaint.setCcCreattiem(new Date());
        constructionComplaintService.insertConstructionComplaint(constructionComplaint);
        return AjaxResult.success(constructionComplaint);
    }

    /**
     * 修改施工投诉
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:edit')")
    @Log(title = "施工投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionComplaint constructionComplaint)
    {
        return toAjax(constructionComplaintService.updateConstructionComplaint(constructionComplaint));
    }

    /**
     * 删除施工投诉
     */
//    @PreAuthorize("@ss.hasPermi('system:complaint:remove')")
    @Log(title = "施工投诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ccIds}")
    public AjaxResult remove(@PathVariable Long[] ccIds)
    {

        return toAjax(constructionComplaintService.deleteConstructionComplaintByIds(ccIds));
    }
}
